//
//  PwdResetViewController.m
//  baiduhealth
//
//  Created by longcheng on 14-7-14.
//  Copyright (c) 2014年 Baidu. All rights reserved.
//

#import "PwdResetViewController.h"
#import "PwdForgetViewController.h"
//#import "HTTPFacade.h"
//#import "BaseRequestModel.h"
//#import "UserManage.h"
//#import "BDImage.h"
//#import "ImageDefine.h"
//#import "UserRequestModel.h"
//#import "BaseViewController.h"
//#import "UINavigationItem+CustomTitleLabel.h"

#import "UIColor+JRDNote.h"
#import "UIColor-Adaptive.h"
#import "StringHelper.h"
//#import "LoginDefine.h"

#define TAG_PWD_CONFIRM 3

@interface PwdResetViewController ()

@property (nonatomic, copy) NSString *vCodeStr;

@end

@implementation PwdResetViewController {
    NSInteger _verifyCount;
    NSTimer *_verifyTime;
    NSString *_phonenum;
    NSString *_password;
    BOOL _isPwdShow;
    UIView *_backView;
}

@synthesize emailFromFgtPwd = _emailFromFgtPwd;
@synthesize txtVerifyCode = _txtVerifyCode;
@synthesize sendCodeBtn = _sendCodeBtn;
@synthesize lableErrCode = _lableErrCode;
@synthesize ImageErrCode = _ImageErrCode;
@synthesize txtPwdReset = _txtPwdReset;
@synthesize txtPwdResetCfm = _txtPwdResetCfm;
@synthesize pwdShowBtn = _pwdShowBtn;
@synthesize finishBtn = _finishBtn;
@synthesize finishActicity = _finishActicity;
@synthesize vCodeStr;

- (void)dealloc
{
    if (_verifyTime) {
        [_verifyTime invalidate];
    }
    _verifyTime = nil;
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    _txtPwdReset.delegate = self;
    _txtPwdResetCfm.delegate = self;
    _txtPwdResetCfm.tag = TAG_PWD_CONFIRM;
    _txtVerifyCode.delegate = self;
    _pwdShowBtn.exclusiveTouch = YES;

    [self iniView];
    [self initLabel];
    [self initGesture];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardShow) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardHide) name:UIKeyboardWillHideNotification object:nil];
}

- (void)iniView {
    /*[self.navigationItem setCustomeTitle:JrdLocalizedString(@"S:SmartBand2:login_reset_password", nil)];
    self.navigationController.navigationBar.barTintColor = [UIColor JRDColorNavGrayBg];

    self.navigationController.navigationBar.barTintColor = [UIColor JRDColorNavGrayBg];
    [self setLeftItemImage:[UIImage imageNamed:@"ic_arrow_left"]
             selectedImage:[UIImage imageNamed:@"ic_arrow_left"]
                    target:self
                    action:@selector(doneBack:)];*/

    _txtPwdReset.secureTextEntry = YES;
    _txtPwdReset.returnKeyType = UIReturnKeyNext;
    _txtPwdReset.keyboardType = UIKeyboardTypeASCIICapable;
    _txtPwdReset.font = [UIFont fontWithName:@"HelveticaNeue" size:18.0f];//cici 11-20
    _txtPwdResetCfm.font = [UIFont fontWithName:@"HelveticaNeue" size:18.0f];// set the same font
    _txtPwdResetCfm.secureTextEntry = YES;
    _txtPwdResetCfm.returnKeyType = UIReturnKeyDone;
    _txtPwdResetCfm.keyboardType = UIKeyboardTypeASCIICapable;

    _sendCodeBtn.titleLabel.numberOfLines = 1;//cici 10-30
    _sendCodeBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
    _sendCodeBtn.titleLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:18.0f];
    NSString *str = @"login_pwd_resend";//JrdLocalizedString(@"S:SmartBand2:login_pwd_resend", nil);
    [_sendCodeBtn setTitle:str forState:UIControlStateNormal];
    //    _sendCodeBtn.titleLabel.text = str;
    _sendCodeBtn.backgroundColor = [UIColor clearColor];

    [self initTextView];

    [self initFinishBtn];
    
    [self startTimer];
}

- (void)doneBack:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark-- initView
- (void)initLabel {
    [self.inputPwdLabel setText:@"Enter new Password"];
    [self.inputVerifyLabel setText:@"set register password"];
    [self.conformPwdLable setText:@"enter confirm password"];
    self.passwordLimitLabel.text = @"register password error";
    self.passwordLimitLabel.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:14.0];
}

- (void)initTextView {
    [self setTextField:_txtVerifyCode backImage:nil placeHoler:@"input hint" clearButtonMode:UITextFieldViewModeWhileEditing keyboardType:UIKeyboardTypeNumberPad returnKeyType:UIReturnKeyNext];

    [self setTextField:_txtPwdReset backImage:nil placeHoler:NSLocalizedString(@"login_input_password_hint", nil) clearButtonMode:UITextFieldViewModeNever keyboardType:UIKeyboardTypeASCIICapable returnKeyType:UIReturnKeyNext];

    [self setTextField:_txtPwdResetCfm backImage:nil placeHoler:@"confirm password"clearButtonMode:UITextFieldViewModeWhileEditing keyboardType:UIKeyboardTypeASCIICapable returnKeyType:UIReturnKeyDone];
}

- (void)setTextField:(UITextField *)textField
           backImage:(NSString *)bgImage
          placeHoler:(NSString *)placeHolder
     clearButtonMode:(UITextFieldViewMode)clearButtonMode
        keyboardType:(UIKeyboardType)keyboardType
       returnKeyType:(UIReturnKeyType)returnKeyType {

    textField.layer.cornerRadius = 25.f;
    //textField.layer.cornerRadius = 25.0f;
    textField.borderStyle = UITextBorderStyleNone;
    textField.layer.backgroundColor = [UIColor JRDColorLoginTextGray].CGColor;

    textField.placeholder = placeHolder;
    textField.clearButtonMode = clearButtonMode;
    textField.returnKeyType = returnKeyType;
    textField.keyboardType = keyboardType;
}

- (void)initFinishBtn {
    _finishBtn.backgroundColor = [UIColor JRDColorStandardBlue];
    _finishBtn.layer.cornerRadius = 25.0f;
    //    _finishBtn.layer.borderWidth = 1.0f;

    _finishBtn.titleLabel.numberOfLines = 0;
    NSString *finishStr = @"login_reset_password";
    [_finishBtn setTitle:finishStr forState:UIControlStateNormal];
}

#pragma mark Email VerifyCode
- (void)setBackgroundViewBlur {
    if (!_backView) {
        _backView = [[UIView alloc] init];
    }
    
    _backView.translatesAutoresizingMaskIntoConstraints = NO;
    _backView.backgroundColor = [UIColor blackColor];
    _backView.alpha = 0.5;
    _backView.center = self.view.center;
    _backView.frame = [[UIScreen mainScreen] bounds];
    
    UITapGestureRecognizer *cancelGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(cancelResendActCodeAction)];
    cancelGesture.delegate = self;
    cancelGesture.numberOfTapsRequired = 1;
    cancelGesture.numberOfTouchesRequired = 1;
    cancelGesture.cancelsTouchesInView = NO;
    [_backView addGestureRecognizer:cancelGesture];
    
//    UIWindow *window = [[UIApplication sharedApplication] keyWindow];
    [self.view addSubview:_backView];
}

- (void)cancelResendActCodeAction {
    [self dismissAlertView];
}

- (void)dismissAlertView {
    
    dispatch_async(dispatch_get_main_queue(), ^{
        if (self.verCodeAlertView && _backView) {
            [self.verCodeAlertView removeFromSuperview];
            
            [_backView removeFromSuperview];
            self.view.frame = [[UIScreen mainScreen]bounds];
        }
    });
}

- (IBAction)getVerifyCodeClick:(id)sender {
    [_txtVerifyCode resignFirstResponder];
    [_txtPwdReset resignFirstResponder];
    [_txtPwdResetCfm resignFirstResponder];
    
    //set background blur effect
    [self setBackgroundViewBlur];
    
    [self setResendActivationCodeAlert];
    
    //fresh captha
    [self getCaptchaImg];
}

- (IBAction)vertificationCodeBtnAction:(id)sender {
    [self getVerifyCodeEvent];
}

- (void)setResendActivationCodeAlert {
    [self setResendLabel];
    [self setResendButton];
    
    //set view
    [self.verCodeAlertView setSize:CGSizeMake(280, 150)];
    self.verCodeAlertView.layer.cornerRadius = 8.0f;
    self.verCodeAlertView.layer.masksToBounds = YES;
    self.verCodeAlertView.backgroundColor = [UIColor whiteColor];
    
//    UIWindow *window = [[UIApplication sharedApplication] keyWindow];
    [self.view addSubview:self.verCodeAlertView];
    self.verCodeAlertView.center = self.view.center;
}

- (void)setResendLabel {
    NSString *title = @"iputtvc";//JrdLocalizedString(@"S:SmartBand2:iputtvc", nil);
    
    self.codeTitleLabel.text = title;
    self.codeTextfield.layer.cornerRadius = 5.0f;
    self.codeTextfield.placeholder = @"login_input_captcha_set_hint";//JrdLocalizedString(@"S:SmartBand2:login_input_captcha_set_hint", nil);
    self.codeTextfield.text = nil;
    self.codeTextfield.delegate = self;
    self.codeImageView.image = nil;
}

- (void)setResendButton {
    NSString *resnedStr = @"str_activation_submit";//JrdLocalizedString(@"S:SmartBand2:str_activation_submit", nil);
    
    UIImage *white = [self imageFromColor:[UIColor whiteColor]];
    [self.codeBtn setBackgroundImage:white forState:UIControlStateHighlighted];
    [self.codeBtn setBackgroundImage:white forState:UIControlStateNormal];
    
    [self.codeBtn setTitle:resnedStr forState:UIControlStateNormal];
    [self.codeBtn.layer setCornerRadius:10.0f];
}

//get image with pure color
- (UIImage *)imageFromColor:(UIColor *)color {
    CGRect rect = CGRectMake(0, 0, 1, 1);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return image;
}

#pragma mark - getCaptchaImg
- (void)getCaptchaImg {
    
   /* [self setcaptchaActivityWithStatus:CAPTCHA_START];
    
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        
        HttpCallBack *callback = [[HttpCallBack alloc] init];
        callback.doneBlock = ^(id result, NSUInteger tag) {
            if ([result isKindOfClass:[UserRequestModel class]]) {
                UserRequestModel *model = (UserRequestModel *)result;
                if ([model errorCode] != 0) {
                    
                    [self makeErrCode:model.errorMsg];
                    [self setcaptchaActivityWithStatus:CAPTCHA_END];
                    
                } else {
                    self.vCodeStr = model.vcodeStr;
                    [self getCapthaImageWithUrl:model.vcodeURL];
                }
            } else if ([result isKindOfClass:[BaseRequestModel class]]) {
                NSString *errorStr = JrdLocalizedString(@"S:SmartBand2:getcapthafailed", nil);
                [self makeErrCode:errorStr];
                [self setcaptchaActivityWithStatus:CAPTCHA_END];
            }
        };
        
        [[UserManage sharedUserManage] getCaptchaWithCallback:callback];
    });*/
}

- (void)getCapthaImageWithUrl:(NSString *)url {
    
   /* [BDImage getImageWithNSUrl:url completion:^(UIImage *image) {
        [self setcaptchaActivityWithStatus:CAPTCHA_END];
        if (image) {
            UIImage *cImage = image;
            self.codeImageView.image = cImage;
            CGRect codeRect = self.codeImageView.frame;
            [self.codeImageView setFrame:codeRect];
        }
    }];*/
}

- (void)setcaptchaActivityWithStatus:(NSInteger)captchaStatus {
   /* if (CAPTCHA_START == captchaStatus) {
        self.refreshImageIndicator.hidden = NO;
        [self.refreshImageIndicator startAnimating];
    } else {
        self.refreshImageIndicator.hidden = YES;
        [self.refreshImageIndicator stopAnimating];
    }*/
}

#pragma mark -
- (void)getVerifyCodeEvent
{
    [self pwdFindBackFromWebWithBlock:^(BOOL isSuccess, NSString *error) {
        if (!isSuccess) {
            NSString *error = @"str_login_verification_error";//JrdLocalizedString(@"S:SmartBand2:str_login_verification_error", nil);
//            NSString *check = JrdLocalizedString(@"S:SmartBand2:str_network_no_connection", nil);
            NSString *reminder = [NSString stringWithFormat:@"%@", error];
            [self makeErrCode:reminder];
        } else {
            [self dismissAlertView];
            [self startTimer];
        }
    }];
}

- (void)pwdFindBackFromWebWithBlock:(void (^)(BOOL isSuccess, NSString *error))resuleBlock {
    NSString *email = _emailFromFgtPwd;
    NSString *captcha = self.codeTextfield.text;
    
    if(captcha.length == 0){
        NSString *errorStr = @"pleaseicaptha";//JrdLocalizedString(@"S:SmartBand2:pleaseicaptha", nil);
        [self makeErrCode:errorStr];
        return;
    }
    
    [SVProgressHUD showWithMaskType:SVProgressHUDMaskTypeClear];
    
    /*HttpCallBack *callback = [[HttpCallBack alloc] init];
    callback.doneBlock = ^(id result, NSUInteger tag) {
        if ([result isKindOfClass:[UserRequestModel class]]) {
            [SVProgressHUD dismiss];
            UserRequestModel *model = (UserRequestModel *)result;
            if ( 1 != model.status ) {
                NSString *errorStr;
                NSString* status = [NSString stringWithFormat:@"%@", [model attributeForKey:@"status"]];
                if ([status isEqualToString:@"-5"]) {
                    errorStr = JrdLocalizedString(@"S:SmartBand2:str_login_verification_error", nil);
                    self.codeTextfield.text = nil;
                    [self getCaptchaImg];
                } else {
                    errorStr = JrdLocalizedString(@"S:SmartBand2:str_user_not_exist_error", nil);
                }
                resuleBlock(NO, errorStr);
            } else {
                resuleBlock(YES, nil);
            }
        }
    };
    [[UserManage sharedUserManage] loginForgetPassword:email imageID:self.vCodeStr imageCode:captcha callback:callback];*/
}

- (void)startTimer
{
    _verifyCount = 30;
    _sendCodeBtn.enabled = NO;
    
    if (!_verifyTime) {
        [self.sendCodeBtn setTitle:@"" forState:UIControlStateNormal];
        _verifyTime = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(doneTimer) userInfo:nil repeats:YES];
    }
}

- (void)doneTimer {
    _verifyCount--;
    NSString *str = [NSString stringWithFormat:@"%ld", (long)_verifyCount];
    _sendCodeBtn.titleLabel.text = str;
    [_sendCodeBtn setTitle:str forState:UIControlStateNormal];

    if (_verifyCount == 0) {
        NSString *str = @"login_pwd_resend";//JrdLocalizedString(@"S:SmartBand2:login_pwd_resend", nil);
        [_sendCodeBtn setTitle:str forState:UIControlStateNormal];
        _sendCodeBtn.enabled = YES;

        if (_verifyTime) {
            [_verifyTime invalidate];
            _verifyTime = nil;
        }
    }
}

/* send verifyCode */
/*
- (void)verfifyCodeConform {
    BOOL rel = NO;
    PwdForgetViewController *pwdForgetVCForEmail = [[PwdForgetViewController alloc] init];
    NSString *email = pwdForgetVCForEmail.txtEmail.text;
    NSString *captcha = pwdForgetVCForEmail.txtCaptcha.text;
    NSString *imageID = pwdForgetVCForEmail.vCodeStr;

    if ([self.txtVerifyCode.text length] == 0) {
        [self makeErrCode:JrdLocalizedString(@"S:SmartBand2:pleaseievc", nil)];
        [self.txtVerifyCode becomeFirstResponder];
        return;
    }

    if (rel == NO) {
        HttpCallBack *callbacke = [[HttpCallBack alloc] init];
        callbacke.doneBlock = ^(id result, NSUInteger tag) {
            //validateResponseAndTip(result);
            BaseRequestModel *model = result;
            if (0 != model.errorCode) {
                [self makeErrCode:model.errorMsg];
            }else{
                [self.presentingViewController.presentingViewController dismissViewControllerAnimated:YES completion:nil];
            }
        };
        [[UserManage sharedUserManage] loginForgetPassword:email imageID:imageID imageCode:captcha callback:callbacke];
    }
}
 */

- (void)makeErrCode:(NSString *)errcode {
    if ([errcode length] > 0) {
        NSString *str = [NSString stringWithFormat:@"%@", errcode];
//        [SVProgressHUD showErrorWithStatus:str duration:1.5];
        //[SVProgressHUD showErrorInView:self.view WithStatus:str duration:1.5];

    }
}

#pragma textField
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [_txtVerifyCode resignFirstResponder];
    [_txtPwdReset resignFirstResponder];
    [_txtPwdResetCfm resignFirstResponder];
    [self.codeTextfield resignFirstResponder];

    if (textField.tag == TAG_PWD_CONFIRM) {
        [self finishBtn:nil];
    }
    return YES;
}

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
    return YES;
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    if ([string isEqualToString:@" "]) {
        return NO;
    }
    if ([string isEqualToString:@""]) {
        return YES;
    }
    if (textField == self.txtPwdReset || textField == self.txtPwdResetCfm) {
        if (textField.text.length >= 16) {
            [self makeErrCode:@"str_register_password_error2"];//JrdLocalizedString(@"S:SmartBand2:str_register_password_error2", nil)];
            return NO;
        }
    }
    if ((textField == self.txtVerifyCode && textField.text.length >= 6) || (textField == self.codeTextfield && textField.text.length >= 4)) {
        return NO;
    }
    return YES;
}

#pragma resetPassword
/* check the password input */
- (BOOL)ispwdInputCorrect {
    NSString *pwdreset = _txtPwdReset.text;
    NSString *pwdresetCfm = _txtPwdResetCfm.text;
    //_txtPwdReset.enabled = NO;
    //_txtPwdResetCfm.enabled = NO;

    if (![pwdreset isEqualToString:pwdresetCfm]) {
        [self makeErrCode:@"passwordnts"];//JrdLocalizedString(@"S:SmartBand2:passwordnts", nil)];
        return NO;
    } else if ([pwdreset length] < 8 || [pwdreset length] > 16) {
        [self makeErrCode:@"str_register_password_error2"];//JrdLocalizedString(@"S:SmartBand2:str_register_password_error2", nil)];
        return NO;
    } else if ([StringHelper isOnlyNumOrCharacter:pwdreset]) {
        [self makeErrCode:@"str_register_password_error1"];//JrdLocalizedString(@"S:SmartBand2:str_register_password_error1", nil)];
        return NO;
    } else
        return YES;
}

/* show/hiden  password*/
- (IBAction)pwdShowBtn:(id)sender {
    _pwdShowBtn.selected = !_pwdShowBtn.selected;
    
    if (!_pwdShowBtn.selected) {
        _txtPwdReset.secureTextEntry = YES;
        _txtPwdResetCfm.secureTextEntry = YES;
        
        [_pwdShowBtn setImage:[UIImage imageNamed:@"field_pass_invisible"] forState:UIControlStateNormal];
        [_pwdShowBtn setImage:[UIImage imageNamed:@"field_pass_invisible"] forState:UIControlStateSelected];
        
    } else {
        _txtPwdReset.secureTextEntry = NO;
        _txtPwdResetCfm.secureTextEntry = NO;
        
        [_pwdShowBtn setImage:[UIImage imageNamed:@"field_pass_visible"] forState:UIControlStateNormal];
        [_pwdShowBtn setImage:[UIImage imageNamed:@"field_pass_visible"] forState:UIControlStateSelected];
    }
    _txtPwdReset.selectedTextRange = nil;
    _txtPwdResetCfm.selectedTextRange = nil;
}

/* finish button */
- (IBAction)finishBtn:(id)sender {

    BOOL isValid = [self isInputValid];
    if (!isValid) {
        return;
    }

    NSString *verifyCode = _txtVerifyCode.text;
    NSString *newPassword = _txtPwdReset.text;
    NSString *newPasswordRepeat = _txtPwdResetCfm.text;
    //[SVProgressHUD showWithStatus: @"str_bluetooth_connecting"/*JrdLocalizedString(@"S:SmartBand2:str_bluetooth_connecting", nil) */ maskType:SVProgressHUDMaskTypeBlack withTimeout:NO];

    if ([self ispwdInputCorrect]) {

        //        [_finishActicity setHidden:NO];
        //        [_finishActicity startAnimating];

        /*HttpCallBack *callback = [[HttpCallBack alloc] init];
        callback.doneBlock = ^(id result, NSUInteger tag) {
            if ([result isKindOfClass:[UserRequestModel class]]) {
                UserRequestModel *model = (UserRequestModel *)result;
                [SVProgressHUD dismiss];
                
                if (model.status == 1) {
                    [self turnToLoginViewConroller];
                }else if (model.status == 0){
                    NSString *str = JrdLocalizedString(@"S:SmartBand2:str_login_verification_error", nil);
                    [self makeErrCode:str];
                }else{
                    
                    NSString *str = [NSString stringWithFormat:@"%@ %@", JrdLocalizedString(@"S:SmartBand2:str_register_password_error1", nil), JrdLocalizedString(@"S:SmartBand2:str_register_password_error2", nil)];
                    [self makeErrCode:str];
                }

            }
        };
        [[UserManage sharedUserManage] loginResetPassword:_emailFromFgtPwd
                                               verifyCode:verifyCode
                                              newPassword:newPassword
                                        newPasswordRepeat:newPasswordRepeat
                                                 callback:callback];*/
    }
}

- (BOOL)isInputValid {
    NSString *verifyCode = _txtVerifyCode.text;
    NSString *newPassword = _txtPwdReset.text;
    NSString *newPasswordRepeat = _txtPwdResetCfm.text;
    if ([verifyCode length] == 0) {
        [self makeErrCode:@"pleaseicaptha"];//JrdLocalizedString(@"S:SmartBand2:pleaseicaptha", nil)];
        return NO;
    }
    
    if ([newPassword length] == 0) {
        [self makeErrCode:@"Passwordisnull"];//JrdLocalizedString(@"S:SmartBand2:Passwordisnull", nil)];
        return NO;
    }

    if ([newPassword length] < 8 || [newPassword length] > 16) {
        [self makeErrCode:@"str_register_password_error2"];//JrdLocalizedString(@"S:SmartBand2:str_register_password_error2", nil)];
        return NO;
    }
    
    if ([StringHelper isOnlyNumOrCharacter:newPassword]) {
        [self makeErrCode:@"str_register_password_error1"];//JrdLocalizedString(@"S:SmartBand2:str_register_password_error1", nil)];

        return NO;
    }
    if ([newPassword length] < 8 || ![newPassword isEqualToString:newPasswordRepeat]) {
        [self makeErrCode:@"passwordnts"];//JrdLocalizedString(@"S:SmartBand2:passwordnts", nil)];
        return NO;
    }

    return YES;
}

- (void)turnToLoginViewConroller {
    [self.pwdForgetVC returnToLastView];
}

#pragma mark dismiss keyboard when tap on margin
- (void)initGesture {
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboard)];
    [self.view addGestureRecognizer:tap];
}

- (void)dismissKeyboard {
    [self.view endEditing:YES];
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    if ([touch.view isKindOfClass:[UITextField class]]) {
        return NO;
    }

    return YES;
}

#pragma mark - 
- (void)keyboardShow
{
    if (_backView) {
        self.verCodeAlertView.center = CGPointMake(self.view.center.x, self.view.center.y - 80);
    }
}

- (void)keyboardHide
{
    if (_backView) {
        self.verCodeAlertView.center = CGPointMake(self.view.center.x, self.view.center.y);
    }
}

@end
